﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
using Business;

namespace BaseWeb
{
    public partial class Horizontal_Menu : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindMenu();
            }
        }

        /// <summary>
        /// 生成按钮
        /// </summary>
        private void BindMenu()
        {
            List<li_Menu> arrayMenu = CommonSystem.Instance.Service.GetListByWhere<li_Menu>(c => c.ParentKeyId == "0").OrderBy(c => c.OrderIndex).ToList();
            foreach (var enMenu in arrayMenu)
            {
                MenuItem newItem = new MenuItem() { Text = enMenu.Name, NavigateUrl = "#", Value = enMenu.KeyId };
                BindChild(newItem);
                this.Menu1.Items.Add(newItem);
            }
        }

        private void BindChild(MenuItem parentItem)
        {
            List<li_Menu> arrayMenu = CommonSystem.Instance.Service.GetListByWhere<li_Menu>(c => c.ParentKeyId == parentItem.Value).OrderBy(c => c.OrderIndex).ToList();
            foreach (var enMenu in arrayMenu)
            {
                MenuItem newItem = new MenuItem() { Text = enMenu.Name, NavigateUrl = "#", Value = enMenu.KeyId };
                BindChild(newItem);
                parentItem.ChildItems.Add(newItem);
            }
        }
    }
}
